// $ANTLR 3.1.3 Mar 17, 2009 19:23:44 ValWalker.g 2010-01-30 20:46:32

package org.concepts.java.antlr.validator;

import java.util.Map;
import java.util.HashMap;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

public class ValWalker extends TreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "SPECIALCHARACTERS", "ALPHANUMERIC", "EQUAL", "QUOTE", "DOLLAR", "LPAREN", "RPAREN", "COMMA", "STRING", "PLUS", "MINUS", "MULTIPLY", "DIVIDE", "GT", "LT", "GTE", "LTE", "EQ", "NEQ", "AND", "OR", "NOT", "WHITESPACE", "NEWLINE", "SINGLE_COMMENT", "MULTI_COMMENT", "EXPR", "VARIABLES", "VARIABLE", "NAME", "VALUE", "FUNCTION", "PARAM"
    };
    public static final int DOLLAR=8;
    public static final int FUNCTION=35;
    public static final int LT=18;
    public static final int GTE=19;
    public static final int MULTI_COMMENT=29;
    public static final int WHITESPACE=26;
    public static final int PARAM=36;
    public static final int NOT=25;
    public static final int VALUE=34;
    public static final int MINUS=14;
    public static final int AND=23;
    public static final int EOF=-1;
    public static final int LTE=20;
    public static final int LPAREN=9;
    public static final int QUOTE=7;
    public static final int RPAREN=10;
    public static final int NAME=33;
    public static final int NEQ=22;
    public static final int EXPR=30;
    public static final int NEWLINE=27;
    public static final int VARIABLE=32;
    public static final int MULTIPLY=15;
    public static final int COMMA=11;
    public static final int ALPHANUMERIC=5;
    public static final int EQUAL=6;
    public static final int OR=24;
    public static final int VARIABLES=31;
    public static final int GT=17;
    public static final int PLUS=13;
    public static final int SINGLE_COMMENT=28;
    public static final int EQ=21;
    public static final int SPECIALCHARACTERS=4;
    public static final int DIVIDE=16;
    public static final int STRING=12;

    // delegates
    // delegators


        public ValWalker(TreeNodeStream input) {
            this(input, new RecognizerSharedState());
        }
        public ValWalker(TreeNodeStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        

    public String[] getTokenNames() { return ValWalker.tokenNames; }
    public String getGrammarFileName() { return "ValWalker.g"; }



     /**
      * Map of variables
      */
     Map<String,String> variables = new HashMap<String,String>(); 

     /**
      * Returns true if the String passed in 'true'. The match
      * is done in a case insensitive manner after trimming all the
      * whitespace.
      * @param data can be null.
      */
     private boolean isTrue(String data) {
       if (data != null &&
           (
             data.trim().equalsIgnoreCase("true") ||
             data.trim().equalsIgnoreCase("yes")
           ) 
           ) {
         return true;
       }
       return false;
     }

     /**
      * Parses the data and returns an integer. RuntimeException is
      * thrown if the data passed in is not a number.
      * @param data can be null. 
      */
     private int getNumber(String data) {
       try {
        return Integer.parseInt(data.trim());
       } catch(Throwable e) {
         throw new RuntimeException("Data [" + data + "]" +
         " is not a number", e);
       }
     }

     /**
      * Calls the function.
      *
      * Only two simple functions (length & matches) have been implemented
      * . Typically this method could use Reflection to let user call static
      * methods in Java classes. Support for user defined functions can also
      * be easily added.
      *
      */
     private String callFunction(String funcName, List<String> params) {
       if ("length".equalsIgnoreCase(funcName)) {
         return params.get(0).length() + "";
       } else if ("matches".equalsIgnoreCase(funcName)) {
         String data1 = params.get(0);
         String data2 = params.get(1);
         return data1.matches(data2) + ""; 
       } else {
         throw new RuntimeException(funcName + " function is not supported");
       }
     }




    // $ANTLR start "validator"
    // ValWalker.g:77:1: validator returns [boolean pass = false;] : ^( VARIABLES ( variableDeclaration )* ) ^( EXPR result= expr ) ;
    public final boolean validator() throws RecognitionException {
        boolean pass =  false;;

        String result = null;


        try {
            // ValWalker.g:78:3: ( ^( VARIABLES ( variableDeclaration )* ) ^( EXPR result= expr ) )
            // ValWalker.g:78:5: ^( VARIABLES ( variableDeclaration )* ) ^( EXPR result= expr )
            {
            match(input,VARIABLES,FOLLOW_VARIABLES_in_validator54); 

            if ( input.LA(1)==Token.DOWN ) {
                match(input, Token.DOWN, null); 
                // ValWalker.g:78:17: ( variableDeclaration )*
                loop1:
                do {
                    int alt1=2;
                    int LA1_0 = input.LA(1);

                    if ( (LA1_0==VARIABLE) ) {
                        alt1=1;
                    }


                    switch (alt1) {
                	case 1 :
                	    // ValWalker.g:78:17: variableDeclaration
                	    {
                	    pushFollow(FOLLOW_variableDeclaration_in_validator56);
                	    variableDeclaration();

                	    state._fsp--;


                	    }
                	    break;

                	default :
                	    break loop1;
                    }
                } while (true);


                match(input, Token.UP, null); 
            }
            match(input,EXPR,FOLLOW_EXPR_in_validator61); 

            match(input, Token.DOWN, null); 
            pushFollow(FOLLOW_expr_in_validator67);
            result=expr();

            state._fsp--;


            match(input, Token.UP, null); 

                pass =  isTrue(result);
              

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return pass;
    }
    // $ANTLR end "validator"


    // $ANTLR start "variableName"
    // ValWalker.g:84:1: variableName returns [String variable = \"\";] : first= ALPHANUMERIC (second= ALPHANUMERIC | third= SPECIALCHARACTERS )* ;
    public final String variableName() throws RecognitionException {
        String variable =  "";;

        CommonTree first=null;
        CommonTree second=null;
        CommonTree third=null;

        try {
            // ValWalker.g:85:3: (first= ALPHANUMERIC (second= ALPHANUMERIC | third= SPECIALCHARACTERS )* )
            // ValWalker.g:85:5: first= ALPHANUMERIC (second= ALPHANUMERIC | third= SPECIALCHARACTERS )*
            {
            first=(CommonTree)match(input,ALPHANUMERIC,FOLLOW_ALPHANUMERIC_in_variableName96); 
            variable += first;
            // ValWalker.g:86:4: (second= ALPHANUMERIC | third= SPECIALCHARACTERS )*
            loop2:
            do {
                int alt2=3;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==ALPHANUMERIC) ) {
                    alt2=1;
                }
                else if ( (LA2_0==SPECIALCHARACTERS) ) {
                    alt2=2;
                }


                switch (alt2) {
            	case 1 :
            	    // ValWalker.g:86:6: second= ALPHANUMERIC
            	    {
            	    second=(CommonTree)match(input,ALPHANUMERIC,FOLLOW_ALPHANUMERIC_in_variableName109); 
            	    variable += second;

            	    }
            	    break;
            	case 2 :
            	    // ValWalker.g:88:5: third= SPECIALCHARACTERS
            	    {
            	    third=(CommonTree)match(input,SPECIALCHARACTERS,FOLLOW_SPECIALCHARACTERS_in_variableName129); 
            	    variable += third;

            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return variable;
    }
    // $ANTLR end "variableName"


    // $ANTLR start "value"
    // ValWalker.g:92:1: value returns [String val = \"\";] : (first= STRING | (second= ALPHANUMERIC | third= SPECIALCHARACTERS )+ );
    public final String value() throws RecognitionException {
        String val =  "";;

        CommonTree first=null;
        CommonTree second=null;
        CommonTree third=null;

        try {
            // ValWalker.g:93:3: (first= STRING | (second= ALPHANUMERIC | third= SPECIALCHARACTERS )+ )
            int alt4=2;
            int LA4_0 = input.LA(1);

            if ( (LA4_0==STRING) ) {
                alt4=1;
            }
            else if ( ((LA4_0>=SPECIALCHARACTERS && LA4_0<=ALPHANUMERIC)) ) {
                alt4=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 4, 0, input);

                throw nvae;
            }
            switch (alt4) {
                case 1 :
                    // ValWalker.g:93:5: first= STRING
                    {
                    first=(CommonTree)match(input,STRING,FOLLOW_STRING_in_value158); 
                     val += first;

                    }
                    break;
                case 2 :
                    // ValWalker.g:94:6: (second= ALPHANUMERIC | third= SPECIALCHARACTERS )+
                    {
                    // ValWalker.g:94:6: (second= ALPHANUMERIC | third= SPECIALCHARACTERS )+
                    int cnt3=0;
                    loop3:
                    do {
                        int alt3=3;
                        int LA3_0 = input.LA(1);

                        if ( (LA3_0==ALPHANUMERIC) ) {
                            alt3=1;
                        }
                        else if ( (LA3_0==SPECIALCHARACTERS) ) {
                            alt3=2;
                        }


                        switch (alt3) {
                    	case 1 :
                    	    // ValWalker.g:95:7: second= ALPHANUMERIC
                    	    {
                    	    second=(CommonTree)match(input,ALPHANUMERIC,FOLLOW_ALPHANUMERIC_in_value179); 
                    	    val += second;

                    	    }
                    	    break;
                    	case 2 :
                    	    // ValWalker.g:97:7: third= SPECIALCHARACTERS
                    	    {
                    	    third=(CommonTree)match(input,SPECIALCHARACTERS,FOLLOW_SPECIALCHARACTERS_in_value203); 
                    	    val += third;

                    	    }
                    	    break;

                    	default :
                    	    if ( cnt3 >= 1 ) break loop3;
                                EarlyExitException eee =
                                    new EarlyExitException(3, input);
                                throw eee;
                        }
                        cnt3++;
                    } while (true);


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return val;
    }
    // $ANTLR end "value"


    // $ANTLR start "variableDeclaration"
    // ValWalker.g:101:1: variableDeclaration : ^( VARIABLE ^( NAME var= variableName ) ^( VALUE val= expr ) ) ;
    public final void variableDeclaration() throws RecognitionException {
        String var = null;

        String val = null;


        try {
            // ValWalker.g:105:3: ( ^( VARIABLE ^( NAME var= variableName ) ^( VALUE val= expr ) ) )
            // ValWalker.g:105:6: ^( VARIABLE ^( NAME var= variableName ) ^( VALUE val= expr ) )
            {
            match(input,VARIABLE,FOLLOW_VARIABLE_in_variableDeclaration235); 

            match(input, Token.DOWN, null); 
            match(input,NAME,FOLLOW_NAME_in_variableDeclaration238); 

            match(input, Token.DOWN, null); 
            pushFollow(FOLLOW_variableName_in_variableDeclaration244);
            var=variableName();

            state._fsp--;


            match(input, Token.UP, null); 
            match(input,VALUE,FOLLOW_VALUE_in_variableDeclaration249); 

            match(input, Token.DOWN, null); 
            pushFollow(FOLLOW_expr_in_variableDeclaration255);
            val=expr();

            state._fsp--;


            match(input, Token.UP, null); 

            match(input, Token.UP, null); 

            }


              variables.put(var, val);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "variableDeclaration"


    // $ANTLR start "function"
    // ValWalker.g:109:1: function returns [String result = \"\";] : ^( FUNCTION ^( NAME funcName= ALPHANUMERIC ) ^( PARAM (param= expr )* ) ) ;
    public final String function() throws RecognitionException {
        String result =  "";;

        CommonTree funcName=null;
        String param = null;



          List<String> params = new ArrayList<String>(); 

        try {
            // ValWalker.g:116:3: ( ^( FUNCTION ^( NAME funcName= ALPHANUMERIC ) ^( PARAM (param= expr )* ) ) )
            // ValWalker.g:116:5: ^( FUNCTION ^( NAME funcName= ALPHANUMERIC ) ^( PARAM (param= expr )* ) )
            {
            match(input,FUNCTION,FOLLOW_FUNCTION_in_function292); 

            match(input, Token.DOWN, null); 
            match(input,NAME,FOLLOW_NAME_in_function304); 

            match(input, Token.DOWN, null); 
            funcName=(CommonTree)match(input,ALPHANUMERIC,FOLLOW_ALPHANUMERIC_in_function310); 

            match(input, Token.UP, null); 
            match(input,PARAM,FOLLOW_PARAM_in_function323); 

            if ( input.LA(1)==Token.DOWN ) {
                match(input, Token.DOWN, null); 
                // ValWalker.g:118:17: (param= expr )*
                loop5:
                do {
                    int alt5=2;
                    int LA5_0 = input.LA(1);

                    if ( ((LA5_0>=SPECIALCHARACTERS && LA5_0<=ALPHANUMERIC)||LA5_0==DOLLAR||(LA5_0>=STRING && LA5_0<=OR)||LA5_0==FUNCTION) ) {
                        alt5=1;
                    }


                    switch (alt5) {
                	case 1 :
                	    // ValWalker.g:118:18: param= expr
                	    {
                	    pushFollow(FOLLOW_expr_in_function330);
                	    param=expr();

                	    state._fsp--;

                	     params.add(param);

                	    }
                	    break;

                	default :
                	    break loop5;
                    }
                } while (true);


                match(input, Token.UP, null); 
            }

            match(input, Token.UP, null); 

            }


              result = callFunction((funcName!=null?funcName.getText():null), params);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return result;
    }
    // $ANTLR end "function"


    // $ANTLR start "expr"
    // ValWalker.g:123:1: expr returns [String result = \"true\";] : ( ^( OR first= expr second= expr ) | ^( AND first= expr second= expr ) | ^( EQ first= expr second= expr ) | ^( NEQ first= expr second= expr ) | ^( GT first= expr second= expr ) | ^( LT first= expr second= expr ) | ^( GTE first= expr second= expr ) | ^( LTE first= expr second= expr ) | ^( PLUS first= expr second= expr ) | ^( MINUS first= expr second= expr ) | ^( MULTIPLY first= expr second= expr ) | ^( DIVIDE first= expr second= expr ) | ^( DOLLAR first= variableName ) | first= function | ALPHANUMERIC | STRING | SPECIALCHARACTERS );
    public final String expr() throws RecognitionException {
        String result =  "true";;

        CommonTree ALPHANUMERIC1=null;
        CommonTree STRING2=null;
        CommonTree SPECIALCHARACTERS3=null;
        String first = null;

        String second = null;


        try {
            // ValWalker.g:124:3: ( ^( OR first= expr second= expr ) | ^( AND first= expr second= expr ) | ^( EQ first= expr second= expr ) | ^( NEQ first= expr second= expr ) | ^( GT first= expr second= expr ) | ^( LT first= expr second= expr ) | ^( GTE first= expr second= expr ) | ^( LTE first= expr second= expr ) | ^( PLUS first= expr second= expr ) | ^( MINUS first= expr second= expr ) | ^( MULTIPLY first= expr second= expr ) | ^( DIVIDE first= expr second= expr ) | ^( DOLLAR first= variableName ) | first= function | ALPHANUMERIC | STRING | SPECIALCHARACTERS )
            int alt6=17;
            switch ( input.LA(1) ) {
            case OR:
                {
                alt6=1;
                }
                break;
            case AND:
                {
                alt6=2;
                }
                break;
            case EQ:
                {
                alt6=3;
                }
                break;
            case NEQ:
                {
                alt6=4;
                }
                break;
            case GT:
                {
                alt6=5;
                }
                break;
            case LT:
                {
                alt6=6;
                }
                break;
            case GTE:
                {
                alt6=7;
                }
                break;
            case LTE:
                {
                alt6=8;
                }
                break;
            case PLUS:
                {
                alt6=9;
                }
                break;
            case MINUS:
                {
                alt6=10;
                }
                break;
            case MULTIPLY:
                {
                alt6=11;
                }
                break;
            case DIVIDE:
                {
                alt6=12;
                }
                break;
            case DOLLAR:
                {
                alt6=13;
                }
                break;
            case FUNCTION:
                {
                alt6=14;
                }
                break;
            case ALPHANUMERIC:
                {
                alt6=15;
                }
                break;
            case STRING:
                {
                alt6=16;
                }
                break;
            case SPECIALCHARACTERS:
                {
                alt6=17;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 6, 0, input);

                throw nvae;
            }

            switch (alt6) {
                case 1 :
                    // ValWalker.g:124:5: ^( OR first= expr second= expr )
                    {
                    match(input,OR,FOLLOW_OR_in_expr366); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr372);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr378);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                            if (isTrue(first) || isTrue(second)) {
                              result = "true";
                            } else {
                              result = "false";
                            }
                        

                    }
                    break;
                case 2 :
                    // ValWalker.g:132:5: ^( AND first= expr second= expr )
                    {
                    match(input,AND,FOLLOW_AND_in_expr392); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr398);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr404);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          if (isTrue(first) && isTrue(second)) {
                            result = "true";
                          } else {
                            result = "false";
                          }
                        

                    }
                    break;
                case 3 :
                    // ValWalker.g:140:5: ^( EQ first= expr second= expr )
                    {
                    match(input,EQ,FOLLOW_EQ_in_expr418); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr424);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr430);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          if (first.equals(second)) {
                            result = "true";
                          } else {
                            result = "false";
                          }
                        

                    }
                    break;
                case 4 :
                    // ValWalker.g:148:5: ^( NEQ first= expr second= expr )
                    {
                    match(input,NEQ,FOLLOW_NEQ_in_expr444); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr450);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr456);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          if (!first.equals(second)) {
                            result = "true";
                          } else {
                            result = "false";
                          }
                        

                    }
                    break;
                case 5 :
                    // ValWalker.g:156:5: ^( GT first= expr second= expr )
                    {
                    match(input,GT,FOLLOW_GT_in_expr470); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr476);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr482);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          if (getNumber(first) >  getNumber(second)) {
                            result = "true";
                          } else {
                            result = "false";
                          }
                        

                    }
                    break;
                case 6 :
                    // ValWalker.g:164:5: ^( LT first= expr second= expr )
                    {
                    match(input,LT,FOLLOW_LT_in_expr496); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr502);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr508);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          if (getNumber(first) <  getNumber(second)) {
                            result = "true";
                          } else {
                            result = "false";
                          }
                        

                    }
                    break;
                case 7 :
                    // ValWalker.g:172:5: ^( GTE first= expr second= expr )
                    {
                    match(input,GTE,FOLLOW_GTE_in_expr522); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr528);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr534);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          if (getNumber(first) >=  getNumber(second)) {
                            result = "true";
                          } else {
                            result = "false";
                          }
                        

                    }
                    break;
                case 8 :
                    // ValWalker.g:180:5: ^( LTE first= expr second= expr )
                    {
                    match(input,LTE,FOLLOW_LTE_in_expr548); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr554);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr560);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          if (getNumber(first) <=  getNumber(second)) {
                            result = "true";
                          } else {
                            result = "false";
                          }
                        

                    }
                    break;
                case 9 :
                    // ValWalker.g:188:5: ^( PLUS first= expr second= expr )
                    {
                    match(input,PLUS,FOLLOW_PLUS_in_expr574); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr580);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr586);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          result  = (getNumber(first) +  getNumber(second)) + ""; 
                        

                    }
                    break;
                case 10 :
                    // ValWalker.g:192:5: ^( MINUS first= expr second= expr )
                    {
                    match(input,MINUS,FOLLOW_MINUS_in_expr600); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr606);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr612);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          result  = (getNumber(first) -  getNumber(second)) + ""; 
                        

                    }
                    break;
                case 11 :
                    // ValWalker.g:196:5: ^( MULTIPLY first= expr second= expr )
                    {
                    match(input,MULTIPLY,FOLLOW_MULTIPLY_in_expr626); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr632);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr638);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          result  = (getNumber(first) *  getNumber(second)) + ""; 
                        

                    }
                    break;
                case 12 :
                    // ValWalker.g:200:5: ^( DIVIDE first= expr second= expr )
                    {
                    match(input,DIVIDE,FOLLOW_DIVIDE_in_expr652); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr658);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr664);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          result  = (getNumber(first) /  getNumber(second)) + ""; 
                        

                    }
                    break;
                case 13 :
                    // ValWalker.g:204:5: ^( DOLLAR first= variableName )
                    {
                    match(input,DOLLAR,FOLLOW_DOLLAR_in_expr678); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_variableName_in_expr684);
                    first=variableName();

                    state._fsp--;


                    match(input, Token.UP, null); 

                          result  = variables.get(first);
                          if (result == null) {
                            throw new RuntimeException("Variable with name [" + first +
                            "] not defined by the used.");
                          }
                        

                    }
                    break;
                case 14 :
                    // ValWalker.g:212:5: first= function
                    {
                    pushFollow(FOLLOW_function_in_expr701);
                    first=function();

                    state._fsp--;


                          result = first;
                        

                    }
                    break;
                case 15 :
                    // ValWalker.g:216:5: ALPHANUMERIC
                    {
                    ALPHANUMERIC1=(CommonTree)match(input,ALPHANUMERIC,FOLLOW_ALPHANUMERIC_in_expr713); 

                          result = (ALPHANUMERIC1!=null?ALPHANUMERIC1.getText():null);
                        

                    }
                    break;
                case 16 :
                    // ValWalker.g:220:5: STRING
                    {
                    STRING2=(CommonTree)match(input,STRING,FOLLOW_STRING_in_expr725); 

                          result = ((STRING2!=null?STRING2.getText():null)).replaceAll("\"","");
                        

                    }
                    break;
                case 17 :
                    // ValWalker.g:224:5: SPECIALCHARACTERS
                    {
                    SPECIALCHARACTERS3=(CommonTree)match(input,SPECIALCHARACTERS,FOLLOW_SPECIALCHARACTERS_in_expr737); 

                          result = (SPECIALCHARACTERS3!=null?SPECIALCHARACTERS3.getText():null);
                        

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return result;
    }
    // $ANTLR end "expr"

    // Delegated rules


 

    public static final BitSet FOLLOW_VARIABLES_in_validator54 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_variableDeclaration_in_validator56 = new BitSet(new long[]{0x0000000100000008L});
    public static final BitSet FOLLOW_EXPR_in_validator61 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_validator67 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_ALPHANUMERIC_in_variableName96 = new BitSet(new long[]{0x0000000000000032L});
    public static final BitSet FOLLOW_ALPHANUMERIC_in_variableName109 = new BitSet(new long[]{0x0000000000000032L});
    public static final BitSet FOLLOW_SPECIALCHARACTERS_in_variableName129 = new BitSet(new long[]{0x0000000000000032L});
    public static final BitSet FOLLOW_STRING_in_value158 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ALPHANUMERIC_in_value179 = new BitSet(new long[]{0x0000000000000032L});
    public static final BitSet FOLLOW_SPECIALCHARACTERS_in_value203 = new BitSet(new long[]{0x0000000000000032L});
    public static final BitSet FOLLOW_VARIABLE_in_variableDeclaration235 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_NAME_in_variableDeclaration238 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_variableName_in_variableDeclaration244 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_VALUE_in_variableDeclaration249 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_variableDeclaration255 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_FUNCTION_in_function292 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_NAME_in_function304 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ALPHANUMERIC_in_function310 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_PARAM_in_function323 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_function330 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_OR_in_expr366 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr372 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr378 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_AND_in_expr392 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr398 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr404 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_EQ_in_expr418 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr424 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr430 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_NEQ_in_expr444 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr450 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr456 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_GT_in_expr470 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr476 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr482 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_LT_in_expr496 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr502 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr508 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_GTE_in_expr522 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr528 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr534 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_LTE_in_expr548 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr554 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr560 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_PLUS_in_expr574 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr580 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr586 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_MINUS_in_expr600 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr606 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr612 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_MULTIPLY_in_expr626 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr632 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr638 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_DIVIDE_in_expr652 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr658 = new BitSet(new long[]{0x0000000801FFF138L});
    public static final BitSet FOLLOW_expr_in_expr664 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_DOLLAR_in_expr678 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_variableName_in_expr684 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_function_in_expr701 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ALPHANUMERIC_in_expr713 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_STRING_in_expr725 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_SPECIALCHARACTERS_in_expr737 = new BitSet(new long[]{0x0000000000000002L});

}